//
//  ZFBMomentHeaderView.m
//  生活圈
//
//  Created by heima on 16/6/24.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "Masonry.h"
#import "UILabel+Addition.h"
#import "ZFBMomentHeaderView.h"

@implementation ZFBMomentHeaderView

+ (instancetype)momentHeadrView {
    CGFloat viewH = 185;
    return [[self alloc] initWithFrame:CGRectMake(0, 0, 0, viewH)];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

//- (UILabel*)labelWithText:(NSString*)text andTextColor:(UIColor*)textColor andFontSize:(CGFloat)fontSize
//{
//    UILabel* label = [[UILabel alloc] init];
//    label.text = text;
//    label.textColor = textColor;
//    label.font = [UIFont systemFontOfSize:fontSize];
//    return label;
//}

// 初始化头部视图的子控件
- (void)setupUI {
    // 1.现场label
    //    UILabel* sceneLabel = [[UILabel alloc] init];
    //    sceneLabel.text = @"现场";
    //    sceneLabel.textColor = [UIColor darkGrayColor];
    //    sceneLabel.font = [UIFont systemFontOfSize:14];
    //    [self addSubview:sceneLabel];

    //    UILabel* sceneLabel = [self labelWithText:@"现场" andTextColor:[UIColor darkGrayColor] andFontSize:14];

    UILabel *sceneLabel = [UILabel labelWithText:@"现场" andTextColor:[UIColor darkGrayColor] andFontSize:14];
    [self addSubview:sceneLabel];

    // 2.大图
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"default_nearby_scene"];
    [self addSubview:imageView];

    // 3.朋友动态
    //    UILabel* friendLabel = [[UILabel alloc] init];
    //    friendLabel.text = @"朋友动态";
    //    friendLabel.textColor = [UIColor darkGrayColor];
    //    friendLabel.font = [UIFont systemFontOfSize:14];
    //    [self addSubview:friendLabel];

    //    UILabel* friendLabel = [self labelWithText:@"朋友动态" andTextColor:[UIColor darkGrayColor] andFontSize:14];
    UILabel *friendLabel = [UILabel labelWithText:@"朋友动态" andTextColor:[UIColor darkGrayColor] andFontSize:14];
    [self addSubview:friendLabel];

    // 边距
    CGFloat margin = 8;

    // 自动布局
    [sceneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(margin);
    }];

    CGFloat imageViewHeight = imageView.image.size.height * ([UIScreen mainScreen].bounds.size.width - 2 * margin) / imageView.image.size.width;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sceneLabel.mas_bottom).offset(margin);
        make.left.equalTo(sceneLabel);
        make.right.offset(-margin);
        make.height.offset(imageViewHeight);
    }];

    [friendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(margin);
        make.left.equalTo(imageView);
    }];
}

@end
